package com.app.view.component.room.expressions 
{
	import flash.display.MovieClip;
	import flash.filters.ColorMatrixFilter;
	import flash.events.MouseEvent;
	
	import org.component.item.FlipPageItem;
	import org.component.events.FlipPageEvent;
	import org.component.interfaces.IFlipPageItemData;
	
	import com.peachcastle.core.Display;
	import com.peachcastle.tools.Utils;
	
	import com.app.model.data.ExpressionItemData;
	
	/**
	 * ...
	 * @author kevin
	 */
	public class ExpressionItem extends FlipPageItem
	{
		private var _filter:ColorMatrixFilter = null;
		
		public function ExpressionItem(ui:MovieClip = null) 
		{
			super(ui);
		}
		
		override protected function initialization():void 
		{
			super.initialization();
			assest.buttonMode = true;
			
			_filter = new ColorMatrixFilter(Utils.getGrayMatrix());
		}

		override protected function configureEventListeners():void 
		{
			super.configureEventListeners();
			
			assest.addEventListener(MouseEvent.ROLL_OVER, onExpOver);
			assest.addEventListener(MouseEvent.ROLL_OUT, onExpOut);
			assest.addEventListener(MouseEvent.CLICK, onExpClick);
		}
		private function onExpClick(event:MouseEvent):void
		{
			var evt:FlipPageEvent = new FlipPageEvent(FlipPageEvent.FLIPPAGE_SELECT);
			evt.item = this;
			_subject.dispatchEvent(evt);
			evt =  null;
		}
		private function onExpOver(event:MouseEvent):void
		{
			
			var evt:FlipPageEvent = new FlipPageEvent(FlipPageEvent.FLIPPAGE_OVER);
			evt.item = this;
			_subject.dispatchEvent(evt);
			evt =  null;
		}
		
		private function onExpOut(event:MouseEvent):void
		{
			var evt:FlipPageEvent = new FlipPageEvent(FlipPageEvent.FLIPPAGE_OUT);
			_subject.dispatchEvent(evt);
			evt =  null;
		}
		
		override public function update(data:IFlipPageItemData = null):void 
		{
			super.update(data);
			
			if (assest.numChildren > 1) assest.removeChildAt(1);
			
			var d:ExpressionItemData = ExpressionItemData(data);
			
			var mc:MovieClip = new d.content();
			
			mc.width = mc.height = assest.width;
			assest.addChild(mc);
			
			/*
			if (!d.vip)
			{
				mc.filters = [_filter];
			}
			*/
			
			if (data)
			{
				//ToolTip.register(assest, d.name);
			}
			
		}
		
		override public function dispose():void 
		{
			super.dispose();
			
			if (assest.numChildren > 1)
			{
				assest.removeChildAt(1);
			}
			
			//ToolTip.unregister(assest);
		}

	}

}